package com.whnk.web.controller.pm;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.whnk.common.annotation.Log;
import com.whnk.common.base.AjaxResult;
import com.whnk.common.enums.BusinessType;
import com.whnk.framework.web.base.BaseController;
import com.whnk.framework.web.page.TableDataInfo;
import com.whnk.pm.domain.ProInfo;
import com.whnk.pm.domain.ProMem;
import com.whnk.pm.service.IProInfoService;
import com.whnk.pm.service.IProMemService;

/**
 * 项目在场人员 信息操作处理
 * 
 * @author whwhnk
 * @date 2019-07-25
 */
@Controller
@RequestMapping("/pm/proMem")
public class ProMemController extends BaseController
{
    private String prefix = "pm/proMem";
	
	@Autowired
	private IProMemService proMemService;
	
	@Autowired
	private IProInfoService proInfoService;
	
	@RequiresPermissions("pm:proMem:view")
	@GetMapping()
	public String proMem()
	{
	    return prefix + "/proMem";
	}
	
	/**
	 * 查询项目在场人员列表
	 */
	@RequiresPermissions("pm:proMem:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ProMem proMem)
	{
		startPage();
        List<ProMem> list = proMemService.selectProMemList(proMem);
		return getDataTable(list);
	}
	
	/**
	 * 新增项目在场人员
	 */
	@GetMapping("/add/{proId}")
	public String add(@PathVariable("proId") Integer proId, ModelMap mmap)
	{
		ProInfo proInfo = proInfoService.selectProInfoById(proId);
		mmap.put("proInfo", proInfo);
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存项目在场人员
	 */
	@RequiresPermissions("pm:proMem:add")
	@Log(title = "项目在场人员", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ProMem proMem)
	{		
		return toAjax(proMemService.insertProMem(proMem));
	}

	/**
	 * 修改项目在场人员
	 */
	@GetMapping("/edit/{memId}")
	public String edit(@PathVariable("memId") Integer memId, ModelMap mmap)
	{
		ProMem proMem = proMemService.selectProMemById(memId);
		mmap.put("proMem", proMem);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存项目在场人员
	 */
	@RequiresPermissions("pm:proMem:edit")
	@Log(title = "项目在场人员", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ProMem proMem)
	{		
		return toAjax(proMemService.updateProMem(proMem));
	}
	
	/**
	 * 删除项目在场人员
	 */
	@RequiresPermissions("pm:proMem:remove")
	@Log(title = "项目在场人员", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(proMemService.deleteProMemByIds(ids));
	}
	
	/**
	 * 查看详细信息
	 * 
	 * @param memId
	 * @param mmap
	 * @return
	 */
	@RequiresPermissions("pm:proMem:detail")
    @GetMapping("/detail/{memId}")
    public String detail(@PathVariable("memId") Integer memId, ModelMap mmap)
	{
		ProMem proMem = proMemService.selectProMemById(memId);
		mmap.put("proMem", proMem);
        return prefix + "/detail";
    }
}
